// pages/report_detail/report_detail.js
var app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    navTab: [{
      con: "耳"
    },
    {
      con: "鼻喉"
    },
    {
      con: "鼻"
    },
    {
      con: "喉"
    },
    {
      con: "耳鼻喉"
    },
    {
      con: "耳喉"
    },
    {
      con: "鼻喉"
    },
    {
      con: "耳鼻喉"
    },
    ],
    infoarr: [],
    current: 0,
    reportArr: [{
      title: "血常规五类",
      project: [{
        title: "白细胞",
        values: "5.51  10^9/L",
        now: 126,
        lowStandard: 125,
        highStandard: 250
      },
      {
        title: "血小板",
        values: "369  10^9/L",
        now: 369,
        lowStandard: 125,
        highStandard: 350
      }
      ]
    },
    {
      title: "血常规五类",
      project: [{
        title: "白细胞",
        values: "5.51  10^9/L",
        now: 300,
        lowStandard: 125,
        highStandard: 350
      },
      {
        title: "血小板",
        values: "369  10^9/L",
        now: 349,
        lowStandard: 125,
        highStandard: 350
      },
      {
        title: "血小板",
        images: "/hyb_yl/images/active_01.jpg",
        state: "normal"
      },
      {
        title: "血小板",
        images: "/hyb_yl/images/active_01.jpg",
        state: "abnormal"
      }
      ]
    },
    ],
    pageWrapCount: [],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    var that = this
    var hzid = options.hzid
    //查询bg_id下面的数据
    var bgc = wx.getStorageSync('color')
    wx.setNavigationBarColor({
      frontColor: "#ffffff",
      backgroundColor: bgc,
    })
    // app.globalData.reportArr = that.data.reportArr
    that.setData({

      hzid: hzid
    })
    this.getBginfo(0)
  },
  //导航切换
  navTab: function (e) {
    var that = this
    if (that.removal(that.data.pageWrapCount, e.currentTarget.dataset.index)) {
      that.setData({
        current: e.currentTarget.dataset.index
      })
    } else {
      // that.getBginfo(e.currentTarget.dataset.index)
      // app.globalData.reportArr = that.data.reportArr
      var arrs = that.data.arrs
      var arr = []
      for (var i = 0; i < arrs[e.currentTarget.dataset.index].data.length; i++) {
        arr.push(arrs[e.currentTarget.dataset.index].data[i][0])
      }
      app.globalData.reportArr = arr
      that.setData({
        pageWrapCount: that.data.pageWrapCount.concat([e.currentTarget.dataset.index]),
        current: e.currentTarget.dataset.index
      })
    }

  },
  //去重
  removal: function (arr, str) {
    for (var i = 0, len = arr.length; i < len; i++) {
      if (str == arr[i]) {
        return true
      }
    }
    return false
  },
  //异常
  abnormalClick: function () {
    wx.navigateTo({
      url: '/hyb_yl/mysubpages/pages/abnormal/abnormal',
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  },
  getBginfo: function (index) {
    var that = this
    var hzid = that.data.hzid
    var infoarr = that.data.infoarr
    app.util.request({
      'url': 'entry/wxapp/Bginfo',
      data: {
        hzid: hzid
      },
      success: function (res) {
        console.log(res, index)

        var arrs = res.data.data;
        var arr = []
        for (var i = 0, len = arrs.length; i < len; i++) {
          infoarr.push(arrs[i].name)

        }
        for (var j = 0; j < arrs[0].data.length; j++) {
          arr.push(arrs[0].data[j][0])
        }
        app.globalData.reportArr = arr
        that.setData({
          pageWrapCount: that.data.pageWrapCount.concat([index]),
          infoarr: infoarr,
          arrs: arrs
        })

      }
    })
  }
})